package com.nowcoder.community.entity;

/**
 * @author 韩
 * @version 1.0
 */
public class Page {
    //当前页码
    private int pageNo = 1;
    //每页的数量限制
    private int limit = 10;
    //评论总行数
    private int rows;
    //分页的查询路径，复用
    private String path;

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        if (pageNo >= 1) {
            this.pageNo = pageNo;
        }
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        if (limit >= 1 && limit <= 50) {
            this.limit = limit;
        }
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        if (rows > 0) {
            this.rows = rows;
        }
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    /**
     * 获取当前页的起始行
     *
     * @return
     */
    public int getOffset() {
        return (pageNo - 1) * limit;
    }

    /**
     * 获取总页数
     *
     * @return
     */
    public int getPageTotal() {
        return (rows + limit - 1) / limit;
    }

    public int getStartPage() {
        int start = pageNo - 2;
        return start > 0 ? start : 1;
    }

    public int getEndPage() {
        int end = pageNo + 2;
        int total = getPageTotal();
        return end > total ? total : end;
    }
}
